# !/usr/bin/env python3
# -*- coding: utf-8 -*-

from migrate.versioning import api
from app.config import SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, USERNAME, PASSWORD
from app.models import User
from app import db
import os.path

__author__ = 'InG_byr'

db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))

admin = User(username=USERNAME, password=PASSWORD)
db.session.add(admin)
db.session.commit()
